const axios = require('axios');

const instance = axios.create({
  // baseURL: 'http://152.136.185.210:7878/api/m5'
  baseURL: 'http://152.136.185.210:8000/api/w6'
});

// 拦截器配置
instance.interceptors.request.use(config => {
  // 拼接header/显示请求图标/必须携带一些特殊信息
  return config;
});
instance.interceptors.response.use(result => {
  return result.data;
}, error => {
  console.error(error);
});

module.exports = {
  request: function (config, success = null, failure = null) {
    if (success) {
      instance(config).then(success).catch(err => {
        console.error(err);
        if (failure) {
          failure(err);
        }
      });
    } else {
      return instance(config);
    }
  }
};
